package interfaceUsuario.disciplinaMVC.controle;

import interfaceUsuario.disciplinaMVC.excecao.DisciplinaNaoEncontradaException;
import interfaceUsuario.disciplinaMVC.excecao.DisciplinaSemCodigoException;
import interfaceUsuario.disciplinaMVC.view.DisciplinaView;

import java.util.ArrayList;

import negocio.Disciplina;

public class DisciplinaControlador {
	public static void carregar(DisciplinaView view)
			throws DisciplinaSemCodigoException,
			DisciplinaNaoEncontradaException {
		Disciplina d = view.getDisciplina();
		if (d.getCodigo().equals(" "))
			throw new DisciplinaSemCodigoException();
		else {
			d = new Disciplina(d.getCodigo());
			if (d.getNome() == null)
				throw new DisciplinaNaoEncontradaException();
			else
				view.setDisciplina(d);
		}
	}

	public static void salvar(DisciplinaView view)
			throws DisciplinaSemCodigoException {
		Disciplina d = view.getDisciplina();
		if (!d.getCodigo().equals(" "))
			d.salvar();
		else
			throw new DisciplinaSemCodigoException();
	}

	public static void remover(DisciplinaView view)
			throws DisciplinaSemCodigoException {
		Disciplina d = view.getDisciplina();
		if (!d.getCodigo().equals(" "))
			d.remover();
		else
			throw new DisciplinaSemCodigoException();
	}

	public static String[][] getMatrizDisciplina() {
		ArrayList<Disciplina> disciplinas = Disciplina.getLista();

		String[][] matriz = new String[disciplinas.size()][6];

		int i = 0;
		for (Disciplina d : disciplinas) {
			matriz[i][0] = d.getNome();
			matriz[i][1] = d.getCodigo();
			matriz[i][2] = String.valueOf(d.getCargaHoraria());
			matriz[i][3] = d.getResumo();
			matriz[i][4] = String.valueOf(d.getCreditosTeoricos());
			matriz[i][5] = String.valueOf(d.getCreditosPraticos());

			i++;
		}

		return matriz;
	}
}
